import java.util.ArrayList;
import java.util.Random;

public class Exersice {
    private int count = 50;
    private ArrayList<Equation> equationList;
    public Exersice() {
        equationList = new ArrayList<>();
    }
    public Exersice(int count) {
        this.count = count;
        equationList = new ArrayList<>();
    }

    public boolean isExist(Equation paramEquation){
        return equationList.contains(paramEquation);
    }

    public void generateAddExercise(){
        int i =0;
        while (i<count){
            Equation equation = new AddEquation();
            if (isExist(equation)){
                continue;
            }else {
                equationList.add(equation);
                i++;
            }
        }
    }
    public void generateSubtractExercise(){
        int i =0;
        while (i<count) {
            Equation equation = new SubEquation();
            if (isExist(equation)) {
                continue;
            } else {
                equationList.add(equation);
                i++;
            }
        }
    }
    public  Equation getRandomEquation(){
        Equation equation;
        Random random = new Random();
        if (random.nextInt(2) ==0){
            equation = new AddEquation();
        }else{
            equation = new SubEquation();
        }
        return equation;
    }

    public void generateMixExercise(){
        int i =0;
        while (i<count) {
            Equation equation = getRandomEquation();
            if (isExist(equation)) {
                continue;
            }else{
                equationList.add(equation);
                i++;
            }
        }
    }
    public void printExercise(){
        System.out.println("================");
        System.out.println("算法自动生成器");
        System.out.println("================");
        for (int i = 0; i < equationList.size(); i++) {
            System.out.println("第" + (i+1)+"题： "+equationList.get(i).toString());

        }
    }
    public void printExeriseResult(){
        System.out.println("=================");
        System.out.println("参考答案");
        System.out.println("=================");
        for (int i = 0; i < equationList.size(); i++) {
            System.out.println("第" + (i+1)+"题： "+equationList.get(i).getResult());
        }
    }
}
